import React from 'react';
import DataTable from 'components/DataTable';
import Icon from 'components/Icon';
import Button from 'components/Button';
import Upload from "components/Upload";
import { router } from 'dva';
const { Link } = router;
import { Modal } from "antd";
export default (self, dict) => [
  {
    title: '地址',
    name: 'address',
    tableItem: {},
    formItem: {
      rules: [
        {
          required: true,
          message: '请输入地址'
        },
        {
          pattern: /^[\W\w\u4E00-\u9FA5]{1,250}$/,
          message: '标题只能输入250个字符'
        }
      ]
    }
  },
  {
    title: '风格',
    name: 'style',
    dict: dict.style,
    formItem: {
      type: 'select',
      rules: [
        {
          required: true,
          message: '请选择风格'
        }
      ]
    },
    searchItem: {
      type: 'select'
    }
  },
  {
    title: '风格',
    name: 'style_text',
    tableItem: {},
  },
  {
    title: '面积',
    name: 'area',
    tableItem: {},
    formItem: {
      rules: [
        {
          required: true,
          message: '请输入面积'
        }
      ]
    }
  },
  {
    title: '收藏数',
    name: 'collect_count',
    tableItem: {},
  },
  {
    title: '描述',
    name: 'describe',
    tableItem: {},
    formItem: {
      rules: [
        {
          required: true,
          message: '请输入描述'
        }
      ]
    }
  },
  {
    title: '图片',
    name: 'images',
    tableItem: {
      render: (value, record) => {
        return <DataTable.Oper>
          <Upload name="file" multiple={true} accept="image/*"
            action={"/project_case/house/" + record.id + "/batch_upload_room_images/"}
            data={(file) => {
              return {
                page: file.name.split(".")[0],
              };
            }}
            onChange={(info) => {
              if (info.file.status === "error") {
                Modal.error({
                  title: "内容上传失败",
                  content: (
                    <div>
                      <p>sadasd</p>
                    </div>
                  ),
                  onOk() { },
                });
              } else if (info.file.status === "done") {
              }
            }}
          >
            <Icon type="upload" style={{ color: 'red' }} />
          </Upload>
        </DataTable.Oper>
      }
    }
  },
  {
    title: '直接上传',
    name: 'thumbnail_arr',
    formItem: {
      type: 'upload',
      listType: 'picture',
      action: '/system/upload/?savePath=house', // 后台接口 例：/uploadFile 会走代理
      fileName: 'file', // 后台接收的名字
      rules: [
        {
          required: true,
          message: '请选择图片'
        }
      ],
      maxFileSize: 1000, // 最大限制 kb
      max: 1
    }
  },
  {
    title: '是否完成',
    name: 'is_complete_check',
    dict: [{ code: 1 }],
    formItem: {
      type: 'checkbox',
      initialValue: []
    },
  },
  {
    title: '操作',
    tableItem: {
      width: 180,
      render: (text, record) => (
        <DataTable.Oper>
          <Button tooltip="修改" onClick={e => self.onUpdate(record)}>
            <Icon type="edit" />
          </Button>
          <Button tooltip="删除" onClick={e => self.onDelete(record)}>
            <Icon type="trash" />
          </Button>
          <Button tooltip="房间">
            <Link to={"/house/room?id=" + record.id}>
              <Icon type="home" />
            </Link>
          </Button>
          {/* <Upload
            name="file"
            accept="image/*"
            action={"/project_case/house/" + record.id + "/upload_thumbnail/"}
            onChange={(info) => {
              if (info.file.status === "error") {
                Modal.error({
                  title: "图片上传失败",
                  content: (
                    <div>
                      <p>{info.file.response.message}</p>
                    </div>
                  ),
                  onOk() { },
                });
              }
            }}
          >
            <Button tooltip="上传">
              <Icon type="upload" />
            </Button>
          </Upload> */}
        </DataTable.Oper>
      )
    }
  }
];
